package com.wkm.chainchain.blockchain.block;

import lombok.Data;
import lombok.ToString;
import org.apache.commons.codec.binary.Hex;

import static com.wkm.chainchain.blockchain.util.HashUtil.HASH;

@Data
@ToString
public class BlockHeader {
    /**
     * 前一个区块的区块头hash值
     */
    private String hashPrevBlock;
    /**
     * 包含进本区块的所有Unit构成的哈希Merkle树根
     */
    private String hashMerkleRoot;
    /**
     * 时间戳
     */
    private String timestamp;
    /**
     * 区块高度
     */
    private int height;

    public String getBlockHash() {
        char[] hexRes = Hex.encodeHex(HASH.digest(this.toString().getBytes()));
        return new String(hexRes);
    }
}
